﻿using System.Drawing;

namespace Sl.Support.Forms {
	/// <summary>
	/// 用来给纯色的图标替换颜色。
	/// </summary>
	internal static class IconRecolor {
		/// <summary>
		/// 用来给纯色的图标替换颜色。
		/// </summary>
		/// <param name="old_image">要替换颜色的图标，仅支持单色透明背景图标</param>
		/// <param name="color">替换后的颜色</param>
		/// <returns>替换完成后，返回新的Image作为新图标。</returns>
		internal static Image reColorPng(Image old_image, Color color) {
			Bitmap new_image = new Bitmap(old_image);
			for (int x = 0; x < old_image.Width; x++) {
				for (int y = 0; y < old_image.Width; y++) {
					//使用新颜色和旧图片的透明度赋值给像素
					new_image.SetPixel(x, y, Color.FromArgb(new_image.GetPixel(x, y).A, color));
				}
			}
			return new_image;
		}
	}
}
